package com.ruoyi.project.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysAddress;
import com.ruoyi.project.system.service.ISysAddressService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 地址Controller
 *
 * @author jjp
 * @date 2020-04-22
 */
@RestController
@Api(description = "地址Controller")
@RequestMapping("/system/address")
public class SysAddressController extends BaseController {
    @Autowired
    private ISysAddressService sysAddressService;

    /**
     * 查询地址列表
     */
    @PreAuthorize("@ss.hasPermi('system:address:list')")
    @ApiOperation("查询地址列表")
//    @GetMapping("/list")
    public TableDataInfo list(SysAddress sysAddress) {
        startPage();
        List<SysAddress> list = sysAddressService.selectSysAddressList(sysAddress);
        return getDataTable(list);
    }

    /**
     * 获取地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:address:query')")
    @ApiOperation("获取地址详细信息")
    @GetMapping(value = "/{addressId}")
    public AjaxResult getInfo(@PathVariable("addressId") Long addressId) {
        return AjaxResult.success(sysAddressService.selectSysAddressById(addressId));
    }

    /**
     * 新增地址
     */
    @PreAuthorize("@ss.hasPermi('system:address:add')")
    @ApiOperation("新增地址")
    @Log(title = "地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAddress sysAddress) {
        return toAjax(sysAddressService.insertSysAddress(sysAddress));
    }

    /**
     * 修改地址
     */
    @PreAuthorize("@ss.hasPermi('system:address:edit')")
    @ApiOperation("修改地址")
    @Log(title = "地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAddress sysAddress) {
        return toAjax(sysAddressService.updateSysAddress(sysAddress));
    }

    /**
     * 删除地址
     */
    @PreAuthorize("@ss.hasPermi('system:address:remove')")
    @ApiOperation("删除地址")
    @Log(title = "地址", businessType = BusinessType.DELETE)
    @DeleteMapping("/{addressIds}")
    public AjaxResult remove(@PathVariable Long[] addressIds) {
        return toAjax(sysAddressService.deleteSysAddressByIds(addressIds));
    }
}
